import Auth0Lock from 'auth0-lock'
import { SERVER_ADDRESS, IS_DEV_MODE } from 'env'

const AUTH_CONFIG = {
  domain: 'xingjing.au.auth0.com',
  clientId: 'UhFUT6XkIstG7la5SuO4DqVC5BKB2tbr',
  option: {
    closable: false,
    auth: {
      redirectUrl: `${SERVER_ADDRESS}/auth`,
      responseType: 'token id_token',
      scope: 'openid',
      sso: true,
    },
    language: 'zh',
    languageDictionary: {
      emailInputPlaceholder: 'you@youremail.com',
      title: '请登录',
    },
    allowedConnections: ['github', 'Wechat', 'Username-Password-Authentication'],
    socialButtonStyle: 'big',
    theme: {
      logo: 'https://static.thenounproject.com/png/1278155-200.png',
      authButtons: {
        Wechat: {
          displayName: '微信',
          primaryColor: '#2E8B57',
          foregroundColor: '#FFFFFF',
          icon:
            'https://open.weixin.qq.com/zh_CN/htmledition/res/assets/res-design-download/icon64_wx_logo.png',
        },
      },
    },
    clientBaseUrl: IS_DEV_MODE ? undefined : SERVER_ADDRESS,
    languageBaseUrl: IS_DEV_MODE ? undefined : SERVER_ADDRESS,
  },
}

const lock = new Auth0Lock(AUTH_CONFIG.clientId, AUTH_CONFIG.domain, AUTH_CONFIG.option)

lock.on('authenticated', (authResult) => {
  // Call getUserInfo using the token from authResult
  lock.getUserInfo(authResult.accessToken, (error, profile) => {
    if (error) {
      // Handle error

    }
  })
})

export default lock
